GBML manual / Database

Tables

A table is a spreadsheet of named rows and columns that your code reads by name, so every number of your game can be balanced in one place.

What a table is

A table is a spreadsheet inside your game. Each row has a name (a car, an enemy, a shop item) and each column has a name and a kind of value (a speed, a price, a picture). You make tables in the Database section of the Code tab; each table opens in its own tab, where you fill it in like a spreadsheet.

The point is one place to balance your game. Instead of a 10 buried in an enemy's code, the number lives in the table, and the code asks for it by name.

What a column can hold

KindHolds
numbera number with a decimal part, like 2.5
wholea whole number, like 5
textwords, like FALCON (no longer than the text size in Project Settings)
yesnoyes or no, which code sees as true or false
colora color of the console (three numbers from 0 to 31)
sprite, sound, object, roomone of your own, picked from a list; code gets that sprite, sound, object or room itself

A column can also have a smallest and a biggest allowed value (number and whole columns).

Reading a cell

Name the table, the row and the column, in that order. There are two ways to write it and they mean exactly the same thing:

var s = cars.falcon.top_speed;
var s = db_get(cars, "falcon", top_speed);

See Reading a cell the short way and db_get. A mistake in a name (a row, a column, a table that is not there) is a message that names the closest one you meant.

Names

A table's name is a name for the whole project, like an object or a sprite, so it cannot be the name of an object, sprite, script, room, global variable or macro, or of something GBML already has built in. You are told in plain words when it is, and the other way round: once a table has a name, nothing else in the project can take it.

To reuse a table from another project, use the Add Existing button of the Database section. It brings the sprites, sounds and objects the table's cells name (you can untick any), and gives the table a free name if yours is taken.

Your own variables are not affected: a variable of an object called top_speed is still that variable. A column name only means the column right after a table and a row.

Items in a dialogue

A table of things the player can hold (usually called items) works with the Dialogue designer's Do box: Give item and Take item pick a table, a row of it and a count, and add to or take away from a variable you name, which keeps how many the player has. The same two cards are in the Behaviors designer. Rename the table or the row and the cards follow.

Fixed or varying

By default a column is fixed: it is written into the game itself, reading it is free and it uses no memory. Turn on Varying for a column and the game can change it while it runs. See Varying columns.

See also: Reading a cell the short wayVarying columnsdb_getdb_set